/**
 * 
 */

// コンストラクタ
var Bar = function() {
	// 画像index
	this.img_index = 0;
	// 描画オブジェクト
	this.img = null;
	// 座標位置(左上)
	this.x = 0;
	this.y =　0;
	
	// サイズ(倍率)
	this.wide = 1;
	
	this.w = 100;
	this.h =　25;
	
	this.speed = 5;
	
	this.wait_count  = 0;
	this.left_count  = 0;
	this.right_count = 0;
	
	// その他ステータス
	this.type = OBJ_TYPE_BAR;
	this.target_type = OBJ_TYPE_STAGE;
}


Bar.prototype.append = function(stage) {
	if (this.img == null) {
		switch(this.img_index) {
		case 0:
			this.img = JSGF.factory(JSGF.Sprite, ["../image/bar.png"], this.w * this.wide,this.h);
//			this.img.startAnimation(100);
			this.img.move(this.x,this.y);
			break;
		default:
			break;
		}
	}
	stage.appendSprite(this.img);
}

Bar.prototype.hitcheck = function(target) {
	switch(target.type) {
	case OBJ_TYPE_STAGE:
		if (	this.x < 0 ||
				this.x + this.w*this.wide > target.w)
				{return true;}
		else	{return false;}
	default:
		return false;
	}
	return false;
}

Bar.prototype.hit_callback = function(target, is_subject) {
	switch(target.type) {
	case OBJ_TYPE_STAGE:
		if (this.x < 0) { this.x = 0;}
		else if (this.x+this.w*this.wide > target.w) {this.x = target.w - (this.w*this.wide);}
		break;
	case OBJ_TYPE_BALL:
		if (pls_key & (1<<0)) {		// left
			target.addVec(-0.1, 0);
		}
		if (pls_key & (1<<1)) {		// right
			target.addVec(0.1, 0);
		}
		if (this.wait_count > 20) {
			if (target.speed < 10) {
				target.speed +=　0.1;
			}
		}
		if (this.left_count > 20) {
			target.addVec(0.3, 0);
		}
		if (this.right_count > 20) {
			target.addVec(-0.3, 0);
		}
		target.addVec(0, -0.3);
		break;
	default:
		break;
	}
	return;
}

Bar.prototype.action = function() {
	var is_move = false;
	if (pls_key & (1<<0)) {		// left
		this.x -= this.speed;
		if (this.x < 0) this.x = 0;
		is_move = true;
	}
	if (pls_key & (1<<1)) {		// right
		this.x += this.speed;
		if (this.x+this.w*this.wide > SCREEN_WIDTH) this.x = SCREEN_WIDTH - this.w*this.wide;
		is_move = true;
	}
	// 溜め
	if (is_move) {
		this.wait_count = 0;
	} else {
		this.wait_count++;
	}
	// スマッシュ
	if (pls_key & (1<<3)) {		// a
		this.left_count++;
	} else {
		this.left_count = 0;
	}
	if (pls_key & (1<<5)) {		// d
		this.right_count++;
	} else {
		this.right_count = 0;
	}
	// スキル
	if (this.skill_key()) {		// s
		this.skill_use();
	}
}
Bar.prototype.drawing = function() {
	this.img.move(this.x, this.y);
}

Bar.prototype.skill_key = function() {
	var skill_no = 0;
	switch(skill_no) {
	default:
		return (edge_key & (1<<4))?true:false;
	}
}
Bar.prototype.skill_use = function() {
	var skill_no = 0;
	// スキルデータの持ち方については要検討
}